#include "condition.h"

Condition::Condition(class AbstractNode * cond, class AbstractNode * trueBlock, class AbstractNode * falseBlock) : AbstractNode()
{
	c_cond=cond;
	c_trueBlock=trueBlock;
	c_falseBlock=falseBlock;
}

void Condition::write(GraphStream * s)
{
	this->accept(s);

	fprintf(s->stream,"\tnode_%d [label=\"Condition node\" shape=\"rectangle\"]\n", this->number());
	c_cond->write(s);
	fprintf(s->stream,"\tnode_%d -> node_%d [label=\"condition\"]\n",this->number(),c_cond->number());
	if (c_trueBlock!=NULL){
		c_trueBlock->write(s);
		fprintf(s->stream,"\tnode_%d -> node_%d [label=\"true branch\"]\n",this->number(),c_trueBlock->number());
	}
	if (c_falseBlock!=NULL) {
		c_falseBlock->write(s);
		fprintf(s->stream,"\tnode_%d -> node_%d [label=\"false branch\"]\n",this->number(),c_falseBlock->number());
	}
}

Condition::~Condition(void)
{
	delete c_cond;
	delete c_trueBlock;
	delete c_falseBlock;
}
